package org.yray.io.rocketmqdemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/kafka")
@Slf4j
public class KafkaProducer {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    @GetMapping("/msg/{message}")
    public void sendMessage(@PathVariable("message") String normalMessage) {
        log.info("message received : " + normalMessage);
        kafkaTemplate.send("messages", normalMessage);
        log.info("Kafka message [" + normalMessage + "] send success!");
    }
}